//
//  YiPaiDetailHeaderView.m
//  YJRenter
//
//  Created by 文彬 on 2018/7/11.
//  Copyright © 2018年 文彬. All rights reserved.
//

#import "YiPaiDetailHeaderView.h"
#import "WBLoopScrollView.h"

@interface YiPaiDetailHeaderView()<WBLoopScrollViewDelegate>


@property (strong, nonatomic) WBLoopScrollView *loopScrollView;
@property (strong, nonatomic) UIButton *statueBtn;
@property (strong, nonatomic) UILabel *statueLabel;
@property (strong, nonatomic) UILabel *nameLabel;
@property (strong, nonatomic) UILabel *flagLabel;
@property (strong, nonatomic) UILabel *moneyLabel;
@property (strong, nonatomic) UILabel *countLabel;
@property (strong, nonatomic) UIButton *followBtn;

@end


@implementation YiPaiDetailHeaderView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (id)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        
        [self initControl];
        
        [self setInfo];
    }
    
    return self;
}

- (void)initControl{
    
    self.backgroundColor = kPageBackgroundColor;
    
    [self addSubview:self.loopScrollView];
    [self.loopScrollView layoutPages];
    
    [self initStatueView];
    
    [self initInfoView];
}

- (void)initStatueView{
    UIView *view = [[UIView alloc]init];
    view.backgroundColor = RGBACOLOR(0, 0, 0, 0.5);
    [self addSubview:view];
    [view makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(@0);
        make.height.equalTo(@50);
        make.bottom.equalTo(self.loopScrollView.bottom);
    }];
    

    [view addSubview:self.statueBtn];
    [self.statueBtn makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@0);
        make.height.equalTo(@30);
        make.width.equalTo(@80);
        make.centerY.equalTo(view.centerY).offset(-5);
    }];
    
    [view addSubview:self.statueLabel];
    [self.statueLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@80);
        make.right.equalTo(@-80);
        make.height.equalTo(@30);
        make.centerY.equalTo(view.centerY).offset(-5);
    }];
}

- (void)initInfoView{
    UIView *view  = [[UIView alloc]init];
    view.backgroundColor = [UIColor whiteColor];
    [self addSubview:view];
    [view makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@10);
        make.right.equalTo(@-10);
        make.bottom.equalTo(@0);
        make.height.equalTo(@120);
    }];
    
    UIView *lineView = [[UIView alloc]init];
    lineView.backgroundColor = kLineColor;
    [view addSubview:lineView];
    [lineView makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(@5);
        make.right.equalTo(@-60);
        make.width.equalTo(@0.5);
        make.height.equalTo(@60);
    }];
    
    [view addSubview:self.followBtn];
    [self.followBtn makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@30);
        make.height.equalTo(@60);
        make.top.equalTo(@10);
        make.right.equalTo(@-15);
    }];
    
    
    [view addSubview:self.nameLabel];
    [self.nameLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@5);
        make.right.equalTo(lineView.left);
        make.height.equalTo(@30);
        make.top.equalTo(@5);
    }];
    
    [view addSubview:self.flagLabel];
    [self.flagLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameLabel.left);
        make.right.equalTo(self.nameLabel.right);
        make.top.equalTo(self.nameLabel.bottom).offset(5);
        make.height.equalTo(@20);
    }];
    
    UILabel *messLabel = [[UILabel alloc]init];
    messLabel.font = [UIFont systemFontOfSize:14];
    messLabel.textColor = kSecTitleColor;
    messLabel.text = @"当前价格";
    [view addSubview:messLabel];
    [messLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameLabel.left);
        make.width.equalTo(@80);
        make.height.equalTo(@20);
        make.top.equalTo(self.flagLabel.bottom).offset(5);
    }];
    
    [view addSubview:self.moneyLabel];
    [self.moneyLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@70);
        make.width.equalTo(@200);
        make.centerY.equalTo(messLabel.centerY);
        make.height.equalTo(@30);
    }];
    
    [view addSubview:self.countLabel];
    [self.countLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameLabel.left);
        make.right.equalTo(self.nameLabel.right);
        make.height.equalTo(@20);
        make.top.equalTo(messLabel.bottom).offset(5);
    }];
}

- (void)setInfo{
    self.nameLabel.text = @"三亚湾，海边套房，海景三室";
    self.flagLabel.text = @"意厨 · 优品 · 实拍 · 意居门锁";
    self.moneyLabel.text = @"￥500.00";
    self.statueLabel.text = @"4月25日  10:00  结束";
    self.countLabel.text = @"8人参与     3218次围观     2860人关注";
    [self.statueBtn setTitle:@"正在进行" forState:UIControlStateNormal];
    [self.followBtn setImage:[UIImage imageNamed:@"user_setting"] forState:UIControlStateNormal];
    [self.followBtn setTitle:@"关注" forState:UIControlStateNormal];
}
#pragma mark WBLoopScrollViewDelegate
//总共的页数
- (NSInteger)numOfTotalPageCount
{
    return 1;
}

//单个页面的布局
- (UIView*)viewForPageIndex:(NSInteger)index
{
    UIImageView *view = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, self.loopScrollView.frame.size.width, self.loopScrollView.frame.size.height)];
    view.backgroundColor = [UIColor lightGrayColor];
    [view sd_setImageWithURL:[NSURL URLWithString:@"https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=4036889747,3526425271&fm=27&gp=0.jpg"] placeholderImage:nil options:SDWebImageRetryFailed];
    return view;
}

#pragma mark getter
- (WBLoopScrollView*)loopScrollView{
    if (_loopScrollView==nil) {
        _loopScrollView  = [[WBLoopScrollView alloc]initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height-110) animationDuration:5];
        _loopScrollView.delegate = self;
    }
    return _loopScrollView;
}

- (UIButton*)statueBtn{
    if (_statueBtn==nil) {
        
        _statueBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _statueBtn.backgroundColor = kMainOriginColor;
        [_statueBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _statueBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    }
    return _statueBtn;
}

- (UILabel*)statueLabel{
    if (_statueLabel==nil) {
        
        _statueLabel = [[UILabel alloc]init];
        _statueLabel.font = [UIFont systemFontOfSize:16];
        _statueLabel.textColor = [UIColor whiteColor];
        _statueLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _statueLabel;
}
- (UILabel*)nameLabel{
    if (_nameLabel==nil) {
        
        _nameLabel = [[UILabel alloc]init];
        _nameLabel.font = [UIFont systemFontOfSize:17];
        _nameLabel.textColor = kTitleColor;
    }
    return _nameLabel;
}

- (UILabel*)flagLabel{
    if (_flagLabel==nil) {
        
        _flagLabel = [[UILabel alloc]init];
        _flagLabel.font = [UIFont systemFontOfSize:14];
        _flagLabel.textColor = kSecTitleColor;
    }
    return _flagLabel;
}

- (UILabel*)moneyLabel{
    if (_moneyLabel==nil) {
        
        _moneyLabel = [[UILabel alloc]init];
        _moneyLabel.font = [UIFont systemFontOfSize:17];
        _moneyLabel.textColor = kMainOriginColor;
    }
    return _moneyLabel;
}

- (UILabel*)countLabel{
    if (_countLabel==nil) {
        _countLabel = [[UILabel alloc]init];
        _countLabel.font = [UIFont systemFontOfSize:14];
        _countLabel.textColor = kSecTitleColor;
    }
    return _countLabel;
}

- (UIButton*)followBtn{
    if (_followBtn==nil) {
        
        _followBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_followBtn setTitleColor:kTitleColor forState:UIControlStateNormal];
        _followBtn.titleLabel.font = [UIFont systemFontOfSize:15];
        _followBtn.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 30, 0);
        _followBtn.titleEdgeInsets = UIEdgeInsetsMake(30, -30, 0, 0);
    }
    return _followBtn;
}
@end
